package top.z.template.parse.ast.expression;

import top.z.template.Context;
import top.z.template.Template;
import top.z.template.parse.Ast.Expression;
import top.z.template.parse.Span;

import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

/**
 * List
 */
public class ListLiteral extends Expression {

    public final List<Expression> value;

    public ListLiteral(Span span, List<Expression> value) {
        super(span);
        this.value = value;
    }

    public List<Expression> getValue() {
        return value;
    }

    @Override
    public Object evaluate(Template template, Context context, OutputStream out) throws IOException {
        List<Object> list = new ArrayList<>();
        for (Expression value : value) {
            list.add(value.evaluate(template, context, out));
        }
        return list;
    }
}
